<?php

class DienstcategorieController extends AdminController{
	public function actionIndex(){
		$mDC = new Mapper_DienstCategorie();
		
		$this->categorien = $mDC->getAll();
	}
	
	public function actionAdd(){
		if($this->request->isPost()){
			$mDC = new Mapper_DienstCategorie();
			
			$dienstCategorie = new DienstCategorie();
			if($dienstCategorie = $this->request->createFromPost($dienstCategorie)){
				if($mDC->insert($dienstCategorie)){
					$this->redirect($this->module, $this->controller);
				}
			}
		}
	}
	
	public function actionRemove(){
		if($this->request->hasParam("dienst_categorie_id")){
			$mDC = new Mapper_DienstCategorie();
			
			$this->dienstCategorie = $mDC->get($this->request->getParam("dienst_categorie_id"));
			
			if($this->dienstCategorie->IsInUse){
				$this->redirect($this->module, $this->controller);
			}
			
			if($this->request->hasParam("confirm")){
				try{
					if($mDC->remove($this->dienstCategorie)){
						$this->redirect($this->module, $this->controller);
					}
				}catch(Exception $e){
					
				}
			}
		}else{
			$this->redirect($this->module, $this->controller);
		}
	}
	
	public function actionEdit(){
		if($this->request->hasParam("dienst_categorie_id")){
			$mDC = new Mapper_DienstCategorie();
			
			$this->dienstCategorie = $mDC->get($this->request->getParam('dienst_categorie_id'));
			
			if($this->request->isPost()){
				$dienstCategorie = $this->request->createFromPost($this->dienstCategorie);
				
				if($mDC->update($dienstCategorie)){
					$this->redirect($this->module, $this->controller);
				}
			}
		}else{
			$this->redirect($this->module, $this->controller);
		}
	}
}